<template>
  <div class="wrapper">
    <div class="count">围观人数：{{totalBrowserCount}} 中奖人数：{{ totalcount }}</div>
    <div class="music" @click="isPlay" :class="{'bor':!isplay}">
      <img src="http://rs.static.quanc.com.cn/activies/mfAct/music.png" alt>
    </div>
    <div class="wMain">
      <div class="wBtn">
        <div class="shackbtn" @click="shackbtn(0)">
          <img src="http://rs.static.quanc.com.cn/activies/mfAct/shackGoods.png" alt>
        </div>
        <div class="houseBtn" @click="shackbtn(1)">
          <img src="http://rs.static.quanc.com.cn/activies/mfAct/housePurchase.png" alt>
        </div>
      </div>
      <div class="prizeBtn" @click="shackbtn(2)">
        <img src="http://rs.static.quanc.com.cn/activies/mfAct/myPrize.png" alt>
      </div>
    </div>
    <share :isshare="isshare"></share>
  </div>
</template>
<script>
import request from "@/utils/request";
//import { mapMutations } from "vuex";
//import wxsdk from "@/utils/wxsdk";
import { mapState, mapMutations } from "vuex";
import wx from "weixin-js-sdk";
import * as config from "./config";
import Cookies from "js-cookie";
import Share from "@/components/common/Share";

export default {
  data() {
    return {
      totalcount: 0,
      totalBrowserCount: 0,
      reOpenid: "",
      openid: Cookies.get("openid"),
      isplay: false,
      isshare: false,
      paths: [
        {
          path: "/voice"
        },
        {
          path: "/prize"
        }
      ]
    };
  },
  methods: {
    addBroswerCount() {
      let _self = this;
      request
        .get(_self.global.API_URL, {
          action: "/activity/valentine/ValentineAction/addBroswerCount",
          requestParam: {
            actcode: config.ACT_CODE
          }
        })
        .then(response => {});
    },
    getActData() {
      let _self = this;
      request
        .get(_self.global.API_URL, {
          action: "/activity/relay/RelayAction/getActData",
          requestParam: {
            actcode: config.ACT_CODE,
            groupcode: config.ACT_CODE
          }
        })
        .then(response => {
          _self.totalBrowserCount = response.obj.totalBrowserCount * 2;
          _self.totalcount = response.obj.totalcount * 2;
        });
    },
    shackbtn(id) {
      // window.ConfigAudio.pause();
      this.isplay = true;
      // this.$router.push(this.paths[id].path);
      window.location.href =
        location.protocol +
        "//" +
        location.host +
        "/act/ztact" +
        this.paths[id].path +
        "?channel=" +
        this.channel +
        "&reOpenid=" +
        this.reOpenid;
    },
    isPlay() {
      let _self = this;
      if (!_self.isplay) {
        window.ConfigAudio.pause();
        _self.isplay = true;
      } else {
        window.ConfigAudio.play();
        _self.isplay = false;
      }
    },
    ...mapMutations({
      setInfo: "SET_INFO",
      setChannel: "SET_CHANNEL"
    })
  },
  computed: {
    ...mapState(["info", "channel"])
  },
  components: {
    share: Share
  },
  mounted() {
    this.addBroswerCount();
    this.getActData();
    if (!window.ConfigAudio) {
      window.ConfigAudio = new Audio();
      window.ConfigAudio.src =
        "http://rs.static.quanc.com.cn/activies/mfAct/2.mp3";
      wx.ready(function() {
        window.ConfigAudio.play();
      });
    } else {
      window.ConfigAudio.src =
        "http://rs.static.quanc.com.cn/activies/mfAct/2.mp3";
      wx.ready(function() {
        window.ConfigAudio.play();
      });
    }

    this.reOpenid = this.$route.query.reOpenid
      ? this.$route.query.reOpenid
      : "";
    let _self = this;
    this.global.SHARE_CALLBACK_OK = function(type) {
      request
        .get(_self.global.API_URL, {
          action: "/activity/relay/RelayAction/share",
          requestParam: {
            actcode: config.ACT_CODE,
            prizecode: "prize_1",
            channel: _self.channel,
            referenceopenid: _self.reOpenid
          }
        })
        .then(response => {});
    };
    config.initShare();
  },
  created() {
    this.isshare = this.$route.query.isShare
      ? this.$route.query.isShare
      : false;
    this.setChannel(this.$route.query.channel ? this.$route.query.channel : 0);
    if (!this.info.mobile) {
      request
        .get(this.global.API_URL, {
          action: "/activity/relay/RelayAction/getActUserInfo",
          requestParam: {
            actcode: config.ACT_CODE,
            referenceopenid: ""
          }
        })
        .then(response => {
          this.setInfo(response.obj);
          if (this.info && this.info.nickname && this.info.nickname != "") {
            this.global.SHARE_TITLE =
              "大力士【" + this.info.nickname + "】摇中大礼，测测你的臂力";
          }
          this.global.SHARE_LINK =
            location.protocol +
            "//" +
            location.host +
            "/act/ztact/index?channel=" +
            this.channel +
            "&reOpenid=" +
            this.openid;
        });
    }
    this.global.SHARE_LINK =
      location.protocol +
      "//" +
      location.host +
      "/act/ztact/index?channel=" +
      this.channel +
      "&reOpenid=" +
      this.openid;
  }
};
</script>
<style lang="stylus" scoped>
@import '~@/assets/styles/mixins.styl';

.wrapper {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  background: url('http://rs.static.quanc.com.cn/activies/mfAct/main.png') repeat center center;
  background-size: 100% 100%;
}

.bor {
  animation: Rotate 1s infinite linear;
}

.music {
  position: absolute;
  top: 0.2rem;
  right: 0.2rem;
  width: 1rem;
  height: 1rem;
}

.music > img {
  width: 100%;
  height: 100%;
}

.wMain {
  position: absolute;
  top: 60%;
  width: 100%;
}

.wBtn {
  display: flex;
}

.wBtn .shackbtn {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
}

.wBtn .shackbtn > img {
  animation: shakes 1s infinite linear;
  display: block;
  size: 2.12rem 2.58rem;
}

.wBtn .houseBtn {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
}

.wBtn .houseBtn > img {
  animation: shakes 1s infinite linear;
  display: block;
  size: 2.12rem 2.58rem;
}

.wMain .prizeBtn {
  padding-top: 0.5rem;
}

.wMain .prizeBtn > img {
  size: 2.25rem 0.98rem;
  display: block;
  margin: 0 auto;
}

@keyframes roll {
  0% {
    transform: rotate(0deg);
  }

  50% {
    transform: rotate(360deg);
  }
}

@keyframes shakes {
  0% {
    transform: rotate(0);
  }

  5% {
    transform: rotate(10deg);
  }

  10% {
    transform: rotate(-9deg);
  }

  15% {
    transform: rotate(8deg);
  }

  20% {
    transform: rotate(-7deg);
  }

  25% {
    transform: rotate(6deg);
  }

  30% {
    transform: rotate(-5deg);
  }

  35% {
    transform: rotate(4deg);
  }

  40% {
    transform: rotate(-3deg);
  }

  45% {
    transform: rotate(2deg);
  }

  50% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(0deg);
  }
}

@keyframes Rotate {
  from {
    transform: rotate(360deg);
  }

  to {
    transform: rotate(0deg);
  }
}

.count {
  width: 100%;
  color: #fff;
  position: absolute;
  top: 1.5rem;
  left: 0.5rem;
}
</style>
